import 'dart:math';

import 'package:flutter/material.dart';
import 'package:giwiki/screens/characters_screen.dart';
import 'package:giwiki/screens/settings.dart';
import 'package:giwiki/screens/settings_screen.dart';
import 'package:giwiki/screens/weapons_screen.dart';

import 'banners_screen.dart';

class HomeScreen extends StatefulWidget {
  const HomeScreen({super.key});

  @override
  State<StatefulWidget> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen>
    with SingleTickerProviderStateMixin {
  final _tabs = const [
    Tab(
      icon: ImageIcon(AssetImage('lib/assets/settings.png')),
      text: '设置',
    ),
    Tab(
      icon: ImageIcon(AssetImage('lib/assets/character.png')),
      text: '角色',
    ),
    Tab(
      icon: ImageIcon(AssetImage('lib/assets/weapon.png')),
      text: '武器',
    ),
    Tab(
      icon: ImageIcon(AssetImage('lib/assets/banner.png')),
      text: '祈愿',
    ),
  ];
  var _idx = 1;
  late final _controller =
      TabController(length: 4, initialIndex: _idx, vsync: this);

  @override
  Widget build(BuildContext context) {

    var rat = 1080.0 / 1920.0 / 3;
    var size = MediaQuery.of(context).size;
    var sw = min(size.width, size.height);
    var sh = max(size.width, size.height);
    int columnInt = 2;
    if (columnCountSetting != 0) {
      columnInt = columnCountSetting;
    } else {
      var column = sw / sh / rat;
      var columnInt = column.floor();
      if (columnInt == 0) {
        columnInt = 1;
      }
    }
    var w = sw / (columnInt + 0.3);

    return Scaffold(
      body: IndexedStack(
        index: _idx,
        children: const [
          SettingsScreen(),
          CharactersScreen(),
          WeaponsScreen(),
          BannersScreen(),
        ],
      ),
      bottomNavigationBar: TabBar(
        controller: _controller,
        overlayColor: WidgetStateProperty.all(Colors.transparent),
        onTap: (idx) {
          setState(() {
            _idx = idx;
          });
        },
        tabs: _tabs,
      ),
    );
  }
}
